package com.ezops.poc.util;

import java.util.List;
import java.util.Map;

/**
 * Utility to log complex objects.
 * 
 * @author vgaurav
 * 
 */
public class LoggerUtil {

	private LoggerUtil() {
		// can not be instantiated
	}

	/**
	 * Get the string representation of hashmap.
	 * 
	 * @param map
	 * @return
	 */

	public static <K, V> String getLoggableFormat(Map<K, V> map) {
		if (map == null || map.isEmpty()) {
			return "";
		}
		StringBuilder message = new StringBuilder();
		for (Map.Entry<K, V> entry : map.entrySet()) {
			message.append(
					String.format("%-5s - %-10s ", entry.getKey(),
							entry.getValue())).append("\n");
		}
		return message.toString();
	}

	/**
	 * Return the string representation of list.
	 * 
	 * @param list
	 * @return
	 */
	public static <K> String getLoggableFormat(List<K> list) {
		if (list == null || list.isEmpty()) {
			return "";
		}
		StringBuilder message = new StringBuilder();
		for (K object : list) {
			message.append(object.toString());
		}
		return message.toString();
	}
}
